#include<bits/stdc++.h>
using namespace std;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
const int N=2e5+5;
typedef vector<int> vi; 
#define pb push_back
typedef long long ll;
typedef long double ld; 
typedef vector<int>  vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main()
{
    int t;
    cin>>t;
    ll sum=0;
    priority_queue<ll,vector<ll>,greater<ll>>q;
    while(t--){
        int op;
        cin>>op;
        if(op==1){
            ll x;
            cin>>x;
            q.push(x-sum);
        }
        else if(op==2){
            ll x;
            cin>>x;
            sum+=x;
        }
        else if(op==3){
            ll res=q.top();
            q.pop();
            cout<<res+sum<<endl;
        }
    }
}